//
//  RuntimeTest.swift
//  EasySwift
//
//  Created by 王隆帅 on 2017/7/10.
//  Copyright © 2017年 王隆帅. All rights reserved.
//

import UIKit

var k_nameKey = "k_nameKey"

extension Person {
    
    var fullName: String? {
        
        get {
            
            return objc_getAssociatedObject(self, &k_nameKey) as? String;
        }
        
        set {
            
            objc_setAssociatedObject(self, &k_nameKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        }
    }
    
}

class RuntimeTest: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.red;
        // Do any additional setup after loading the view.
        
        testMemberVariables();
        
    }
    
    func testMemberVariables() {
        
        let person1 = Person.init();
        
        person1.personName = "王隆帅";
        person1.fullName = "66666";
        
        print(person1.allMemberVariables());
        print(person1.fullName ?? "没有设置");
    }
    
    func testAllMethods() {
        
        let person1 = Person.init();
        
        person1.personName = "王隆帅";
        
        print(person1.allMethods());
    }
    
    func testAllPropertyNamesAndValues() {
        
        let person1 = Person.init();
        
        person1.personName = "王隆帅";
        
        print(person1.allPropertyNamesAndValues());

    }
    
    func testAllProperties() {
        
        let person1 = Person.init();
        
        person1.personName = "王隆帅";
        
        print(person1.allProperties());
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
